package logic

import (
	"context"
	"errors"
	"home-manager/models/mysql"

	"home-manager/homerpc/homerpc"
	"home-manager/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeShowLogic {
	return &HomeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 房屋详情方法
func (l *HomeShowLogic) HomeShow(in *homerpc.HomeShowRequest) (*homerpc.HomeShowResponse, error) {
	// todo: add your logic here and delete this line
	var home mysql.Home

	err := home.HomeShow(mysql.DB, in.HomeId)
	if err != nil {
		return nil, errors.New("该房屋不存在")
	}

	return &homerpc.HomeShowResponse{
		HomeId:      int64(home.ID),
		HomeName:    home.HomeName,
		HomeAddress: home.HomeAddress,
	}, nil
}
